{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Longer Contiguous Segments of Ones than Zeros"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: checkZeroOnes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #哪种连续子字符串更长"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个二进制字符串 <code>s</code> 。如果字符串中由 <code>1</code> 组成的 <strong>最长</strong> 连续子字符串 <strong>严格长于</strong> 由 <code>0</code> 组成的 <strong>最长</strong> 连续子字符串，返回 <code>true</code> ；否则，返回 <code>false</code><em> </em>。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，<code>s = \"<strong>11</strong>01<strong>000</strong>10\"</code> 中，由 <code>1</code> 组成的最长连续子字符串的长度是 <code>2</code> ，由 <code>0</code> 组成的最长连续子字符串的长度是 <code>3</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>注意，如果字符串中不存在 <code>0</code> ，此时认为由 <code>0</code> 组成的最长连续子字符串的长度是 <code>0</code> 。字符串中不存在 <code>1</code> 的情况也适用此规则。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"1101\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>\n",
    "由 <code>1</code> 组成的最长连续子字符串的长度是 2：\"<strong>11</strong>01\"\n",
    "由 <code>0</code> 组成的最长连续子字符串的长度是 1：\"11<strong>0</strong>1\"\n",
    "由 1 组成的子字符串更长，故返回 true 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"111000\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>\n",
    "由 <code>1</code> 组成的最长连续子字符串的长度是 3：\"<strong>111</strong>000\"\n",
    "由<code> 0</code> 组成的最长连续子字符串的长度是 3：\"111<strong>000</strong>\"\n",
    "由 1 组成的子字符串不比由 0 组成的子字符串长，故返回 false 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"110100010\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>\n",
    "由 <code>1</code> 组成的最长连续子字符串的长度是 2：\"<strong>11</strong>0100010\"\n",
    "由 <code>0</code> 组成的最长连续子字符串的长度是 3：\"1101<strong>000</strong>10\"\n",
    "由 1 组成的子字符串不比由 0 组成的子字符串长，故返回 false 。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= s.length <= 100</code></li>\n",
    "\t<li><code>s[i]</code> 不是 <code>'0'</code> 就是 <code>'1'</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [longer-contiguous-segments-of-ones-than-zeros](https://leetcode.cn/problems/longer-contiguous-segments-of-ones-than-zeros/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [longer-contiguous-segments-of-ones-than-zeros](https://leetcode.cn/problems/longer-contiguous-segments-of-ones-than-zeros/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"1101\"', '\"111000\"', '\"110100010\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        def f(x):\n",
    "            ans = i = 0\n",
    "            while i < n:\n",
    "                if s[i] != x:\n",
    "                    i += 1\n",
    "                    continue\n",
    "                start = i\n",
    "                i += 1\n",
    "                while i < n and s[i - 1] == s[i]:\n",
    "                    i += 1\n",
    "                ans = max(ans, i - start)\n",
    "            return ans\n",
    "        return f(\"1\") > f(\"0\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        a, b = 0, 0\n",
    "        x, y = 0, 0\n",
    "        for ch in s:\n",
    "            if ch == '1':\n",
    "                x += 1\n",
    "                y = 0\n",
    "                a = max(a, x)\n",
    "            else:\n",
    "                y += 1\n",
    "                x = 0\n",
    "                b = max(b, y)\n",
    "\n",
    "        return a > b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        cnt = {'0': 0, '1': 0}\n",
    "        i = 0\n",
    "        while i < n:\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i < n and s[i] == s[i-1]:\n",
    "                i += 1\n",
    "            cnt[s[start]] = max(cnt[s[start]], i-start)\n",
    "        return cnt['1'] > cnt['0']\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        num = 0\n",
    "        arr0 = 0\n",
    "        arr1 = 0\n",
    "        s += '2'\n",
    "        for i in range(len(s)-1):\n",
    "            num += 1\n",
    "            if s[i] != s[i+1]:\n",
    "                if s[i] == '0':\n",
    "                    arr0 = max(num,arr0)\n",
    "                    num = 0\n",
    "                else:\n",
    "                    arr1 = max(num,arr1)\n",
    "                    num = 0\n",
    "        return arr1>arr0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        res0, res1 = 0, 0\n",
    "        cur0, cur1 = 0, 0\n",
    "        for c in s:\n",
    "            if c == '0':\n",
    "                cur0 += 1\n",
    "                cur1 = 0\n",
    "            else:\n",
    "                cur0 = 0\n",
    "                cur1 += 1\n",
    "            res0 = max(res0, cur0)\n",
    "            res1 = max(res1, cur1)\n",
    "        return res1 > res0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        mx0, mx1 = 0, 0\n",
    "        cnt = 0\n",
    "        prev = '#'\n",
    "        for ch in s:\n",
    "            if prev == ch:\n",
    "                cnt += 1\n",
    "            else:\n",
    "                if prev == '0':\n",
    "                    mx0 = max(mx0, cnt)\n",
    "                if prev == '1':\n",
    "                    mx1 = max(mx1, cnt)\n",
    "                cnt = 1\n",
    "            prev = ch\n",
    "        if prev == '0':\n",
    "            mx0 = max(mx0, cnt)\n",
    "        if prev == '1':\n",
    "            mx1 = max(mx1, cnt)\n",
    "        return mx1 > mx0\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        max0 = 0\n",
    "        max1 = 0\n",
    "\n",
    "        cur0 = 0\n",
    "        cur1 = 0\n",
    "        if s[0] == '0':\n",
    "            cur0 += 1\n",
    "        else:\n",
    "            cur1 += 1\n",
    "        for i in range(1, n):\n",
    "            if s[i] == s[i-1]:\n",
    "                if s[i] == '0':\n",
    "                    cur0 += 1\n",
    "                else:\n",
    "                    cur1 += 1\n",
    "            else:\n",
    "                if s[i] == '0':\n",
    "                    max1 = max(max1, cur1)\n",
    "                    cur1 = 0\n",
    "                    cur0 = 1\n",
    "                else:\n",
    "                    max0 = max(max0, cur0)\n",
    "                    cur0 = 0\n",
    "                    cur1 = 1\n",
    "        max0 = max(max0, cur0)\n",
    "        max1 = max(max1, cur1)\n",
    "\n",
    "        return max1 > max0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        num = 0\n",
    "        arr0 = 0\n",
    "        arr1 = 0\n",
    "        s += '2'\n",
    "        for i in range(len(s)-1):\n",
    "            num += 1\n",
    "            if s[i] != s[i+1]:\n",
    "                if s[i] == '0':\n",
    "                    arr0 = max(num,arr0)\n",
    "                    num = 0\n",
    "                else:\n",
    "                    arr1 = max(num,arr1)\n",
    "                    num = 0\n",
    "        return arr1>arr0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        mx0, mx1 = 0, 0\n",
    "        cnt = 0\n",
    "        # 上个字符\n",
    "        prev = '#'\n",
    "        for ch in s:\n",
    "            # 当前字符与上个字符相等\n",
    "            if prev == ch:\n",
    "                cnt += 1\n",
    "            else:\n",
    "                if prev == '0':\n",
    "                    mx0 = max(mx0, cnt)\n",
    "                elif prev == '1':\n",
    "                    mx1 = max(mx1, cnt)\n",
    "                cnt = 1\n",
    "            prev = ch\n",
    "        # 处理结尾的字符\n",
    "        if prev == '0':\n",
    "            mx0 = max(mx0, cnt)\n",
    "        elif prev == '1':\n",
    "            mx1 = max(mx1, cnt)\n",
    "        return mx1 > mx0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        ans1, ans0 = 0, 0\n",
    "        i, n = 0, len(s)\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and s[j] == s[i]:\n",
    "                j += 1\n",
    "            if s[i] == '1':\n",
    "                ans1 = max(ans1, j - i)\n",
    "            else:\n",
    "                ans0 = max(ans0, j - i)\n",
    "            i = j\n",
    "        return ans1 > ans0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        ans1, ans0 = 0, 0\n",
    "        i, n = 0, len(s)\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and s[j] == s[i]:\n",
    "                j += 1\n",
    "            if s[i] == '1':\n",
    "                ans1 = max(ans1, j - i)\n",
    "            else:\n",
    "                ans0 = max(ans0, j - i)\n",
    "            i = j\n",
    "        return ans1 > ans0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        num = 0\n",
    "        s = s + '2'\n",
    "        arr0 = [0]\n",
    "        arr1 = [0]\n",
    "        for i in range(len(s)-1):\n",
    "            num += 1\n",
    "            if s[i] != s[i+1]:\n",
    "                if s[i] == '0':\n",
    "                    arr0.append(num)\n",
    "                    num = 0\n",
    "                else:\n",
    "                    arr1.append(num)\n",
    "                    num = 0\n",
    "        return max(arr1)>max(arr0)\n",
    "\n",
    "\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        start = 0\n",
    "        cnt0, cnt1 = 0, 0\n",
    "        cmp0, cmp1 = 0, 0\n",
    "        \n",
    "        while start < len(s):\n",
    "\n",
    "            while start < len(s) and  s[start] == '0':\n",
    "                start += 1\n",
    "                cnt0 += 1\n",
    "\n",
    "            while start < len(s) and s[start] == '1':\n",
    "                start += 1\n",
    "                cnt1 += 1 \n",
    "\n",
    "\n",
    "            if cnt0 or cnt1:\n",
    "                cmp0 = max(cmp0, cnt0)\n",
    "                cmp1 = max(cmp1, cnt1)\n",
    "                if start == len(s):\n",
    "                    return cmp1 > cmp0\n",
    "                cnt0 = 0\n",
    "                cnt1 = 0\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        max0 = max1 = 0\n",
    "        i = 0\n",
    "        while i < n:\n",
    "            if s[i] == '0':\n",
    "                start = i\n",
    "                i += 1\n",
    "                while i < n and s[i] == '0':\n",
    "                    i += 1\n",
    "                max0 = max(max0, i - start)\n",
    "            else:\n",
    "                start = i\n",
    "                i += 1\n",
    "                while i < n and s[i] == '1':\n",
    "                    i += 1\n",
    "                max1 = max(max1, i - start)\n",
    "        return max0 < max1\n",
    "                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n1 = s.split('0')\n",
    "        n2 = s.split('1')\n",
    "        n1_max = max([len(n) for n in n1])\n",
    "        n2_max = max([len(n) for n in  n2])\n",
    "        return True if n1_max > n2_max else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        ans1, ans2, i, j = 0, 0, 0, 0\n",
    "        while i < len(s):\n",
    "            if s[i] != '1':\n",
    "                i += 1\n",
    "                continue\n",
    "            start = i \n",
    "            i += 1\n",
    "            while i < len(s) and s[i] == '1':\n",
    "                i += 1\n",
    "            ans1 = max(ans1, i - start)\n",
    "        print(ans1)\n",
    "        while j < len(s):\n",
    "            if s[j] != '0':\n",
    "                j += 1\n",
    "                continue\n",
    "            start = j \n",
    "            j += 1\n",
    "            while j < len(s) and s[j] == '0':\n",
    "                j += 1\n",
    "            ans2 = max(ans2, j - start)\n",
    "        if ans1 > ans2:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        num = 0\n",
    "        arr0 = 0\n",
    "        arr1 = 0\n",
    "        s += '2'\n",
    "        for i in range(len(s)-1):\n",
    "            num += 1\n",
    "            if s[i] != s[i+1]:\n",
    "                if s[i] == '0':\n",
    "                    arr0 = max(num,arr0)\n",
    "                    num = 0\n",
    "                else:\n",
    "                    arr1 = max(num,arr1)\n",
    "                    num = 0\n",
    "        return arr1>arr0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        i,n,a,b=0,len(s),-1,-1\n",
    "        while i<n:\n",
    "            left=i\n",
    "            while i<n-1 and s[i]==s[i+1]:\n",
    "                i+=1\n",
    "            if s[left]=='1':\n",
    "                a=max(a,i-left)\n",
    "            else:\n",
    "                b=max(b,i-left)\n",
    "            i+=1\n",
    "        return a>b\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "\n",
    "        l0, l1 = 0, 0\n",
    "        n = len(s)\n",
    "\n",
    "        i = 0\n",
    "        while i < n:\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i < n and s[i] == s[i-1]:\n",
    "                i += 1\n",
    "            if s[i-1] == '1':\n",
    "                l1 = max(l1, i-start)\n",
    "            else:\n",
    "                l0 = max(l0, i-start)\n",
    "        \n",
    "        if l1 > l0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        # 单循环\n",
    "        # 双循环\n",
    "        s0, s1, i = 0, 0, 0\n",
    "        while i < len(s):\n",
    "            tmp = i\n",
    "            if s[i] == '0':\n",
    "                while i < len(s) and s[i] == '0':\n",
    "                    i += 1\n",
    "                s0 = max(s0, i-tmp)\n",
    "            else:\n",
    "                while i < len(s) and s[i] == '1':\n",
    "                    i += 1\n",
    "                s1 = max(s1, i-tmp)\n",
    "        return True if s1 > s0 else False\n",
    "\n",
    "        # 内置函数法 字符串拆分 统计长度\n",
    "        s0 = max(len(i) for i in s.split('1'))\n",
    "        s1 = max(len(i) for i in s.split('0'))\n",
    "        return True if s1 > s0 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        a, b, m, n = 0, 0, 0, 0\n",
    "        for c in s:\n",
    "            if c == \"0\":\n",
    "                b += 1\n",
    "                a = 0\n",
    "            else:\n",
    "                a += 1\n",
    "                b = 0\n",
    "            m = max(m, a)\n",
    "            n = max(n, b)\n",
    "        return m > n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        len_1, max_1, len_0, max_0 = 0, 0, 0, 0\n",
    "        for i in s:\n",
    "            if i == '0':\n",
    "                len_0 += 1\n",
    "                len_1 = 0\n",
    "            else:\n",
    "                len_1 += 1\n",
    "                len_0 = 0\n",
    "            max_0 = max(len_0, max_0)\n",
    "            max_1 = max(len_1, max_1)\n",
    "        return max_1 > max_0\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        res0, res1 = 0, 0\n",
    "        cur0, cur1 = 0, 0\n",
    "        for c in s:\n",
    "            if c == '0':\n",
    "                cur0 += 1\n",
    "                cur1 = 0\n",
    "            else:\n",
    "                cur0 = 0\n",
    "                cur1 += 1\n",
    "            res0 = max(res0, cur0)\n",
    "            res1 = max(res1, cur1)\n",
    "        return res1 > res0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        d = {'0': 0, '1': 0}\n",
    "        i = 0\n",
    "        while i < n:\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i < n and s[i] == s[i-1]:\n",
    "                i += 1\n",
    "            d[s[start]] = max(d[s[start]], i - start)\n",
    "        return d['1'] > d['0']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "\n",
    "        def check(target):\n",
    "            res = l = 0\n",
    "            while l < n:\n",
    "                if s[l] != target:\n",
    "                    l += 1\n",
    "                    continue\n",
    "                r = l + 1\n",
    "                while r < n and s[r] == target:\n",
    "                    r += 1\n",
    "                res = max(res, r - l)\n",
    "                l = r\n",
    "            return res\n",
    "        \n",
    "        res0, res1 = check('0'), check('1')\n",
    "        return res1 > res0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        s_1 = max(s.split('0'))\n",
    "        s_0 = max(s.split('1'))\n",
    "        return len(s_0) < len(s_1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        # if '1' not in s:\n",
    "        #     return False\n",
    "        # elif '0' not in s:\n",
    "        #     return True\n",
    "        res0,res1=0,0\n",
    "        l,r=0,0\n",
    "        while l<n:\n",
    "            if s[l]=='0':\n",
    "                while r<n and s[r]==s[l]:\n",
    "                    r+=1\n",
    "                res0=max(res0,r-l)\n",
    "            elif s[l]=='1':\n",
    "                while r<n and s[r]==s[l]:\n",
    "                    r+=1\n",
    "                res1=max(res1,r-l)\n",
    "            l=r\n",
    "        return res1>res0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        num = 0\n",
    "        arr0 = 0\n",
    "        arr1 = 0\n",
    "        s += '2'\n",
    "        for i in range(len(s)-1):\n",
    "            num += 1\n",
    "            if s[i] != s[i+1]:\n",
    "                if s[i] == '0':\n",
    "                    arr0 = max(num,arr0)\n",
    "                    num = 0\n",
    "                else:\n",
    "                    arr1 = max(num,arr1)\n",
    "                    num = 0\n",
    "        return arr1>arr0\n",
    "\n",
    "\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        def cal(s:str,ch:str)->int:\n",
    "            ans=0\n",
    "            cnt=0\n",
    "            for i in s:\n",
    "                if i==ch:\n",
    "                    cnt+=1\n",
    "                else:ans=max(ans,cnt);cnt=0\n",
    "            ans=max(ans,cnt)\n",
    "            return ans\n",
    "        return cal(s,'1')>cal(s,'0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        i,n,a,b=0,len(s),0,0\n",
    "        while i<n:\n",
    "            left=i\n",
    "            while i<n-1 and s[i]==s[i+1]:\n",
    "                i+=1\n",
    "            if s[left]=='1':\n",
    "                a=max(a,i-left+1)\n",
    "            else:\n",
    "                b=max(b,i-left+1)\n",
    "            i+=1\n",
    "        return a>b\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        i=0\n",
    "        n=len(s)\n",
    "        yi=0\n",
    "        zer=0\n",
    "        while i<n:\n",
    "            if s[i]=='1':\n",
    "                t=1\n",
    "                for j in range(i+1,n):\n",
    "                    if s[j]!='1':\n",
    "                        i=j-1\n",
    "                        break\n",
    "                    t+=1\n",
    "                yi=max(t,yi)\n",
    "            else:\n",
    "                t=1\n",
    "                for j in range(i+1,n):\n",
    "                    if s[j]!='0':\n",
    "                        i=j-1\n",
    "                        break\n",
    "                    t+=1\n",
    "                zer=max(zer,t)\n",
    "            i+=1\n",
    "        print(yi,zer)\n",
    "        return yi>zer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        # 以0为分隔符                                    以1为分隔符\n",
    "        # key代表函数\n",
    "        return len(max(s.split('0'), key=len)) > len(max(s.split('1'), key=len))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        # 以0为分隔符                                    以1为分隔符\n",
    "        # key代表函数\n",
    "        return len(max(s.split('0'), key=len)) > len(max(s.split('1'), key=len))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        return max(len(string) for string in s.split('0')) > max(len(string) for string in s.split('1'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def get_max(self,words):\n",
    "        return max(len(w) for w in words)\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        # cnt1,cnt0=0,0\n",
    "        # left,right=0,0\n",
    "        # n=len(s)\n",
    "        # while left <n:\n",
    "        #     if s[left]=='1':\n",
    "        #         while right<n and s[right]==s[left]:\n",
    "        #             right+=1\n",
    "        #         cnt1=max(cnt1,right-left)\n",
    "        #         left=right\n",
    "                \n",
    "        #     else:\n",
    "        #         while right<n and s[right]==s[left]:\n",
    "        #             right+=1\n",
    "        #         cnt0=max(cnt0,right-left)\n",
    "        #         left=right\n",
    "                \n",
    "        # return cnt1>cnt0\n",
    "    \n",
    "        \n",
    "        return self.get_max(s.split('0'))>self.get_max(s.split('1'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        nu=[0,0]\n",
    "        nc=[0,0]\n",
    "        for i in range(n):\n",
    "            if i==0 or s[i-1] != s[i]:\n",
    "                if s[i]==\"0\":\n",
    "                    nu[0]=1\n",
    "                else:\n",
    "                    nu[1]=1\n",
    "            else:\n",
    "                if s[i]==\"0\":\n",
    "                    nu[0]+=1\n",
    "                else:\n",
    "                    nu[1]+=1\n",
    "            nc[0]=max(nc[0],nu[0])\n",
    "            nc[1]=max(nc[1],nu[1])\n",
    "        return nc[1]>nc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        nu=[0,0]\n",
    "        nc=[0,0]\n",
    "        for i in range(n):\n",
    "            if i==0 or s[i-1] != s[i]:\n",
    "                if s[i]==\"0\":\n",
    "                    nu[0]=1\n",
    "                else:\n",
    "                    nu[1]=1\n",
    "            else:\n",
    "                if s[i]==\"0\":\n",
    "                    nu[0]+=1\n",
    "                else:\n",
    "                    nu[1]+=1\n",
    "            nc[0]=max(nc[0],nu[0])\n",
    "            nc[1]=max(nc[1],nu[1])\n",
    "        return nc[1]>nc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        ans_1 = ans_0 = 1\n",
    "        i = 0\n",
    "        n = len(s)\n",
    "        while i < n:\n",
    "            start = i\n",
    "            while i < n and s[i] == '1':\n",
    "                i += 1\n",
    "            ans_1 = max(ans_1, i - start + 1)\n",
    "            start = i\n",
    "            while i < n and s[i] == '0':\n",
    "                i += 1\n",
    "            ans_0 = max(ans_0, i - start + 1)\n",
    "        return ans_1 > ans_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        i = 0\n",
    "        ans = [0,0]\n",
    "        while i < n:\n",
    "            temp = i\n",
    "            i+=1\n",
    "            while i < n and s[i] == s[i-1]:\n",
    "                i+=1\n",
    "            ans[int(s[i-1])] = max(ans[int(s[i-1])], i - temp)\n",
    "        return ans[0] < ans[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        # 以0为分隔符                                    以1为分隔符\n",
    "        # key代表函数\n",
    "        return len(max(s.split('0'), key=len)) > len(max(s.split('1'), key=len))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        ans = i = 0\n",
    "        while i < n:\n",
    "            if s[i] != '1':\n",
    "                i += 1\n",
    "                continue\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i < n and s[i] != '0':\n",
    "                i += 1\n",
    "            ans = max(ans,i - start)\n",
    "        res = j = 0\n",
    "        while j < n:\n",
    "            if s[j] != '0':\n",
    "                j += 1\n",
    "                continue\n",
    "            start = j\n",
    "            j += 1\n",
    "            while j < n and s[j] != '1':\n",
    "                j += 1\n",
    "            res = max(res,j - start)\n",
    "        if ans > res:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        return len(max(s.split('0'))) > len(max(s.split('1')))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        dp1=[0]*n\n",
    "        dp0=[0]*n\n",
    "        if s[0]=='1':\n",
    "            dp1[0]=1\n",
    "        else:\n",
    "            dp0[0]=1\n",
    "        for i in range(1,n):\n",
    "            if s[i]=='1':\n",
    "                dp1[i]=dp1[i-1]+1\n",
    "                dp0[i]=0\n",
    "            else:\n",
    "                dp0[i]=dp0[i-1]+1\n",
    "                dp1[i]=0\n",
    "        if max(dp1)>max(dp0):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        if len(s) == 1:\n",
    "            return int(s) == 1\n",
    "        count = [0, 0]\n",
    "        num = 0\n",
    "        n = len(s)\n",
    "        for i in range(n-1):           \n",
    "            if s[i] == s[i+1]:\n",
    "                num += 1\n",
    "            else :\n",
    "                count[int(s[i])] = max(count[int(s[i])], num + 1)\n",
    "                num = 0               \n",
    "        count[int(s[-1])] = max(count[int(s[-1])], num + 1)\n",
    "        return count[1] > count[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        len0=len1=i=0\n",
    "        n = len(s)\n",
    "        is1=False\n",
    "        is0=False\n",
    "        while i<n:\n",
    "            if s[i]=='1':\n",
    "                start1 = i \n",
    "                is1 = True\n",
    "                is0 = False\n",
    "            else:\n",
    "                start0 = i \n",
    "                is1 = False\n",
    "                is0 = True\n",
    "            i+=1\n",
    "            while i<n and s[i]==s[i-1]:\n",
    "                i+=1\n",
    "            if is1:\n",
    "                len1 = max(len1,i-start1) \n",
    "            elif is0:\n",
    "                len0 = max(len0,i-start0) \n",
    "        return len1>len0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "\n",
    "        l0, l1 = 0, 0\n",
    "        n = len(s)\n",
    "\n",
    "        i = 0\n",
    "        while i < n:\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i < n and s[i] == s[i-1]:\n",
    "                i += 1\n",
    "            if s[i-1] == '1':\n",
    "                l1 = max(l1, i-start)\n",
    "            else:\n",
    "                l0 = max(l0, i-start)\n",
    "        \n",
    "        if l1 > l0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        i = 0\n",
    "        max0 = 0\n",
    "        max1 = 0\n",
    "        while i<n:\n",
    "            start = i\n",
    "            while i<n and s[i]=='0':\n",
    "                i+=1\n",
    "            if start!=i and s[i-1]=='0':max0 = max(max0,i-start)\n",
    "            start = i\n",
    "            while i<n and s[i]=='1':\n",
    "                i+=1\n",
    "            if start!=i and s[i-1]=='1': max1 = max(max1,i-start)\n",
    "            \n",
    "        return max0<max1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        cnt1,cnt0=0,0\n",
    "        left,right=0,0\n",
    "        n=len(s)\n",
    "        while left <n:\n",
    "            if s[left]=='1':\n",
    "                while right<n and s[right]==s[left]:\n",
    "                    right+=1\n",
    "                cnt1=max(cnt1,right-left)\n",
    "                left=right\n",
    "                \n",
    "            else:\n",
    "                while right<n and s[right]==s[left]:\n",
    "                    right+=1\n",
    "                cnt0=max(cnt0,right-left)\n",
    "                left=right\n",
    "                \n",
    "        return cnt1>cnt0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        def find_con(s: str, c: str):\n",
    "            res = 0\n",
    "            start, end = 0, 0\n",
    "            while start < len(s):\n",
    "                if s[start] == c:\n",
    "                    while end < len(s) and s[end] == c:\n",
    "                        end += 1\n",
    "                    res = max(res, end - start)\n",
    "                start = end + 1\n",
    "                end = start\n",
    "            return res\n",
    "\n",
    "        zero_cnt = find_con(s, '0')\n",
    "        one_cnt = find_con(s, '1')\n",
    "        return one_cnt > zero_cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        s = list(s)\n",
    "        dp = [0] * (len(s))\n",
    "        dp[0] = 1 if s[0]=='1' else 0\n",
    "        for i in range(1, len(s)):\n",
    "            if s[i]=='0': dp[i] = 0\n",
    "            else: dp[i] = dp[i-1] +1\n",
    "        \n",
    "        dp2 = [0] * (len(s))\n",
    "        dp2[0] = 1 if s[0]=='0' else 0\n",
    "        for i in range(1, len(s)):\n",
    "            if s[i]=='1': dp2[i] = 0\n",
    "            else: dp2[i] = dp2[i-1] +1\n",
    "\n",
    "        maxLen1, maxLen2 = max(dp), max(dp2)\n",
    "        return (maxLen1 > maxLen2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        \n",
    "        def cal(s, ch):\n",
    "            n = len(s)\n",
    "            ans = 0\n",
    "            i = 0\n",
    "            while i < n:\n",
    "                if s[i] != ch:\n",
    "                    i += 1\n",
    "                    continue\n",
    "                l = i\n",
    "                i += 1\n",
    "                while i < n and s[i] == s[i-1]:\n",
    "                    i += 1\n",
    "                ans = max(ans, i - l)\n",
    "            return ans\n",
    "        \n",
    "        return cal(s, '1') > cal(s, '0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        i = 0\n",
    "        start = 0\n",
    "        length = len(s)\n",
    "        res1, res0 = 0, 0\n",
    "        while i <= length-1:\n",
    "            if not s[i] == '1':\n",
    "                i += 1\n",
    "                continue\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i <= length-1 and s[i] == '1':\n",
    "                i += 1\n",
    "            res1 = max(res1, len(s[start : i]))\n",
    "        i = 0\n",
    "        while i <= length-1:\n",
    "            if not s[i] == '0':\n",
    "                i += 1\n",
    "                continue\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i <= length-1 and s[i] == '0':\n",
    "                i += 1\n",
    "            res0 = max(res0, len(s[start : i]))\n",
    "        return True if res1 > res0 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        if s=='1':\n",
    "            return True\n",
    "        if s=='0':\n",
    "            return False\n",
    "        def judge(s,l):\n",
    "            n = len(s)\n",
    "            i = 0\n",
    "            res= 0\n",
    "            while i< n:\n",
    "                if s[i] != l:\n",
    "                    i+=1\n",
    "                    continue\n",
    "                i0 = i\n",
    "                i+=1\n",
    "                while i<n and s[i]==l:\n",
    "                    i+=1\n",
    "                res = max(res,i-i0)\n",
    "            return res\n",
    "        return judge(s,'1') > judge(s,'0')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        if len(s) == 1:\n",
    "            return int(s) == 1\n",
    "        count = [0, 0]\n",
    "        num = 0\n",
    "        n = len(s)\n",
    "        for i in range(n-1):\n",
    "            if s[i] != s[i+1]:\n",
    "                count[int(s[i])] = max(count[int(s[i])], num + 1)\n",
    "                num = 0              \n",
    "            else :\n",
    "                num += 1\n",
    "            \n",
    "        if s[-1] == s[-2]:\n",
    "            count[int(s[-1])] = max(count[int(s[i])], num + 1)\n",
    "        else:\n",
    "            count[int(s[-1])] = max(count[int(s[-1])], 1)\n",
    "\n",
    "\n",
    "        return count[1] > count[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        zero = one = n\n",
    "        while zero >= 0:\n",
    "            if '0' * zero in s:\n",
    "                break\n",
    "            zero -= 1\n",
    "        while one >= 0:\n",
    "            if '1' * one in s:\n",
    "                break\n",
    "            one -= 1\n",
    "        return one > zero"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        i = 0\n",
    "        zeros = ones = 0\n",
    "        while i < n:\n",
    "            start = i\n",
    "            i += 1\n",
    "            while i < n and s[i] == s[start]:\n",
    "                i += 1\n",
    "            if s[start] == '0':\n",
    "                zeros = max(zeros, i - start)\n",
    "            else:\n",
    "                ones = max(ones, i - start)\n",
    "        \n",
    "        return ones > zeros\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        def check_max(flag : int) -> int:\n",
    "            i, n = 0, len(s)\n",
    "            ans = 0\n",
    "            while i < n:\n",
    "                while i < n and s[i] != flag:\n",
    "                    i += 1\n",
    "                if i == n:\n",
    "                    return ans\n",
    "                j = i\n",
    "                i += 1\n",
    "                while i < n and s[i] == flag:\n",
    "                    i += 1\n",
    "                ans = max(ans, i - j)\n",
    "            return ans\n",
    "        return check_max('1') > check_max('0')\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        num = 0\n",
    "        s = s + '2'\n",
    "        arr = {'0': [0], '1': [0]}\n",
    "        for i in range(len(s)-1):\n",
    "            if s[i] == '0':\n",
    "                num += 1\n",
    "            else:\n",
    "                num += 1\n",
    "\n",
    "            if s[i] != s[i+1]:\n",
    "                if s[i] == '0':\n",
    "                    arr['0'].append(num)\n",
    "                    num = 0\n",
    "                else:\n",
    "                    arr['1'].append(num)\n",
    "                    num = 0\n",
    "        return max(arr['1'])>max(arr['0'])\n",
    "\n",
    "\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        i, l0, l1, n = 0, 0, 0, len(s)\n",
    "        while i < n:\n",
    "            if s[i] == \"1\":\n",
    "                start = i\n",
    "                i += 1\n",
    "                while i < n and s[i] == s[i-1]:\n",
    "                    i += 1\n",
    "                l1 = max(l1, i-start)\n",
    "                print(f\"l1={l1}\")\n",
    "            else:\n",
    "                start = i\n",
    "                i += 1\n",
    "                while i < n and s[i] == s[i-1]:\n",
    "                    i += 1\n",
    "                l0 = max(l0, i-start)\n",
    "                print(f\"l0={l0}\")\n",
    "        return l1 > l0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        if len(s) == 1:\n",
    "            return int(s) == 1\n",
    "        count = [0, 0]\n",
    "        num = 0\n",
    "        n = len(s)\n",
    "        for i in range(n-1):\n",
    "            if s[i] != s[i+1]:\n",
    "                count[int(s[i])] = max(count[int(s[i])], num + 1)\n",
    "                num = 0              \n",
    "            else :\n",
    "                num += 1            \n",
    "        count[int(s[-1])] = max(count[int(s[-1])], num + 1)\n",
    "        return count[1] > count[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        ans0 = 0\n",
    "        ans1 = 0\n",
    "        i = 0\n",
    "        n = len(s)\n",
    "        while i<n:\n",
    "            st = i\n",
    "            i+=1\n",
    "            while i<n and s[i]==s[i-1]:\n",
    "                i+=1\n",
    "            if s[st]=='0':\n",
    "                ans0 = max(ans0,i-st)\n",
    "            else:\n",
    "                ans1 = max(ans1,i-st)\n",
    "        return ans1>ans0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        res0,res1 = 0,0\n",
    "        cur0,cur1 = 0,0\n",
    "        for i in s:\n",
    "            if i  == '0':\n",
    "                cur0 += 1\n",
    "                cur1 = 0\n",
    "            else:\n",
    "                cur1 += 1\n",
    "                cur0 = 0\n",
    "            res0 = max(res0,cur0)\n",
    "            res1 = max(res1,cur1)\n",
    "        return res1 > res0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        i = 0\n",
    "        zeros = ones = 0\n",
    "        while i < n:\n",
    "            start = i\n",
    "            while i < n and s[i] == s[start]:\n",
    "                i += 1\n",
    "            if s[start] == '0':\n",
    "                zeros = max(zeros, i - start)\n",
    "            else:\n",
    "                ones = max(ones, i - start)\n",
    "        \n",
    "        return ones > zeros\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        s0 = list(s.split('0'))\n",
    "        s1 = list(s.split('1'))\n",
    "        max1 = max([len(x) for x in s0])\n",
    "        max2 = max([len(y) for y in s1])\n",
    "        return max1 > max2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkZeroOnes(self, s: str) -> bool:\n",
    "        l0 = []\n",
    "        l1 = []\n",
    "        for each in s.split('1'):\n",
    "            l0.append(len(each))\n",
    "        for each in s.split('0'):\n",
    "            l1.append(len(each))\n",
    "        return max(l1) > max(l0)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
